﻿package lobby
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.LocalConnection;
	import flash.events.StatusEvent;
	import lobby.events.LobbyEvent;
	import flash.external.ExternalInterface;
	
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	
	public class BaseLocalConnection extends EventDispatcher
	{
		public var localConnection:LocalConnection;
		public var connectionName:String;
		public var connectionNameSend:String;
		private var isConnect:Boolean = false;
		
		public function BaseLocalConnection()
		{
			
		}
		
		public function init(cName, cNameSend):void
		{
			connectionName = cName;
			connectionNameSend = cNameSend;
			localConnection = new LocalConnection();
			localConnection.allowDomain("*");
			localConnection.allowInsecureDomain("*");
			localConnection.connect(connectionName);
			localConnection.client = this;
			isConnect = true;
			localConnection.addEventListener(StatusEvent.STATUS, onLocalConnectionStatus);
			//trace("init");
		}
		
		public function closeConnect():void
		{
			if (isConnect)
			{
				localConnection.close();
			}
		}
		
		private function onLocalConnectionStatus(statusEvent:StatusEvent):void
		{
			if (statusEvent.level == "error")
			{
				trace(statusEvent.code);
				
			}
		}
	
	}

}